package com.uit.se6.customui.utils;

import android.graphics.Typeface;
import android.os.Build;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class FontUtils {

	private static final int ICE_CREAM_SANDWITCH = 14;

	private static Typeface normal;

	private static void processsViewGroup(ViewGroup v, final int len) {

		for (int i = 0; i < len; i++) {
			final View c = v.getChildAt(i);
			if (c instanceof TextView) {
				setCustomFont((TextView) c);
			} else if (c instanceof ViewGroup) {
				setCustomFont((ViewGroup) c);
			}
		}
	}

	private static void setCustomFont(TextView c) {
		if (normal != null) {
			c.setTypeface(normal);
		}
	}

	public static void setCustomFont(View v, Typeface typeface) {
		normal = typeface;

		if (v instanceof ViewGroup) {
			ViewGroup vg = (ViewGroup) v;
			for (int i = 0; i < vg.getChildCount(); i++) {
				View child = vg.getChildAt(i);
				setCustomFont(child, typeface);
			}
		} else if (v instanceof TextView) {
			setCustomFont(v, typeface);
		}
	}

	private static void setCustomFont(ViewGroup v) {
		final int len = v.getChildCount();
		processsViewGroup(v, len);
	}

	public static Typeface getTypefaceNormal() {
		return normal;
	}
}
